package ModelImplementation

import (
	"time"
	""
)

type CommissionedClassification struct {
	itsCommissionRate float64
	itsSalary float64
	itsReceipts map[time.Time]SalesReceipt
}

func (c *CommissionedClassification)newCommissionedClassification(salary float64, commissionalRate float64)  {
	c.itsSalary = salary
	c.itsCommissionRate = commissionalRate
}

func (c *CommissionedClassification) GetReceipts(date time.Time) SalesReceipt {
	return c.itsReceipts[date]
}

func (c *CommissionedClassification) GetRate() float64 {
	return c.itsCommissionRate
}

func (c *CommissionedClassification) GetSalary() float64 {
	return c.itsSalary
}

func (c *CommissionedClassification) AddSalesReceipt(sr SalesReceipt)  {
	c.itsReceipts[sr.GetSaleDate()] = sr
}

//实现PaymentClassification中的CalculatePay方法
func (c *CommissionedClassification) CalculatePay(pc Model.Paycheck) float64 {
	commission := 0.0

	for key, value := range c.itsReceipts {
		dt1 := pc.GetPayPeriodStartDate()
		dt2 := pc.GetPayPeriodEndDate()
		if key.After(dt1) && key.Before(dt2) {
			commission += value.GetAmount() * c.itsCommissionRate
		}
	}

	return c.itsSalary + commission
}



